package com.example.liangwenli;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;

public class MainAdapter extends RecyclerView.Adapter<MainAdapter.ViewHolder> {

    private final ArrayList<String[]> arrayList;
    private OnItemClickListener onItemClickListener = null;

    public MainAdapter(ArrayList<String[]> arrayList) {
        this.arrayList = arrayList;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.tv_1.setText(arrayList.get(position)[0]);
        holder.tv_2.setText(arrayList.get(position)[1]);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup group, int viewType) {

        View view = LayoutInflater.from(group.getContext()).inflate(R.layout.item_main, group, false);
        return new ViewHolder(view);

    }

    @Override
    public int getItemCount() {

        return arrayList.size();

    }

    @SuppressWarnings("unused")
    public void setOnItemClickListener(OnItemClickListener listener) {

        this.onItemClickListener = listener;

    }

    @SuppressWarnings("unused")
    public interface OnItemClickListener {

    }

    static class ViewHolder extends RecyclerView.ViewHolder {

        private TextView tv_1;
        private TextView tv_2;

        private ViewHolder(View view) {
            super(view);
            this.tv_1=view.findViewById(R.id.tv_1);
            this.tv_2=view.findViewById(R.id.tv_2);
        }

    }

}
